﻿using Process.Infrastructure.Interface;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Process.Infrastructure.Implement
{
    public class BaseRepository<T> : IBaseRepository<T> where T : class, new()
    {
        private readonly ProcessDbContext db;
        private readonly DatabaseContext dl;

        public BaseRepository(ProcessDbContext db, DatabaseContext dl)
        {
            this.db = db;
            this.dl = dl;
        }

        public IQueryable<T> GetAll()
        {
            return db.Set<T>();
        }
        public async Task<int> DeleteAsync(T entity)
        {
            return await dl.SqlSugar.Deleteable(entity).ExecuteCommandAsync();
        }

        public async Task<int> InsertAsync(T entity)
        {
            return await dl.SqlSugar.Insertable(entity).ExecuteCommandAsync();
        }

        public async Task<int> UpdateAsync(T entity)
        {
            return await dl.SqlSugar.Updateable(entity).ExecuteCommandAsync();
        }
    }
}
